package chapter3.lc3;

//LC 3  无重复字符的最长子串

/**
 * 双指针
 * int数组用char做下标
 */
public class LengthOfLongestSubstring {
    private static final int[] map = new int[256];
    public int lengthOfLongestSubstring(String s) {
        int res = 0;
        for (int i = 0, j = -1; i < s.length(); ) {
            if (j < s.length() -1 && map[s.charAt(j+1)] == 0) {
                j++;
                map[s.charAt(j)]++;
                res = Math.max(res, j - i + 1);
            }else {
                map[s.charAt(i)]--;
                i++;
            }
        }
        return res;
    }
}
